package work.getter;

import work.fram.JDBCConnect;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

public class Dept {

    private static Map<String, String> codeName = new HashMap<>();

    private static Map<String, String> nameCode = new HashMap<>();

    static {
        Statement statement = JDBCConnect.getStatement();
        try {
            ResultSet resultSet = statement.executeQuery("SELECT org_name,org_code FROM md_organization ");

            while (resultSet.next()) {
                String org_code = resultSet.getString("org_code");
                String org_name = resultSet.getString("org_name");
                codeName.put(org_code, org_name);
                nameCode.put(org_name, org_code);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static Map<String, String> getCodeName() {
        return codeName;
    }

    public static Map<String, String> getNameCode() {
        return nameCode;
    }

    public static String getCodeByName(String name) {
        return nameCode.get(name);
    }

    public static String getNameByCode(String code) {
        return codeName.get(code);
    }


}
